<?php 
class BaseChartReportForm extends BaseStatsReportForm
{

	protected $display_fields = array('Percentage');
	public function getTemplate(){
		return "chart";
	}


	public function configure(){
		parent::configure();
		unset($this['group_by'],$this['leave_start']);
		unset($this['employee_id'],$this['leave_end']);
		unset($this['order_by']);
		$this->widgetSchema['month_year'] = new sfWidgetFormDate(array('format'=>'<span style="display:none">%day%</span>%month%/%year%','can_be_empty'=>false));

		$this->validatorSchema['month_year'] = new sfValidatorDate();

		$this->widgetSchema['leave_type_id']->setOption('multiple',true);
		$this->validatorSchema['leave_type_id']->setOption('multiple',true);


	}


	protected function addDepartmentIdColumnCriteria(Criteria $criteria, $field, $value=null){
		
		if($value){
			$criteria->addJoin(LinkEmployeeLeavePeer::EMPLOYEE_ID  , EmployeePeer::ID  );
			$criteria->add(EmployeePeer::DEPARTMENT_ID   , $value );
		}
	}

	protected function addSectionIdColumnCriteria(Criteria $criteria, $field, $value=null){
		
		if($value){
			$criteria->addJoin(LinkEmployeeLeavePeer::EMPLOYEE_ID  , EmployeePeer::ID  );
			$criteria->add(EmployeePeer::SECTION_ID  , $value );
		}
	}

	protected function addMonthYearColumnCriteria(Criteria $criteria, $field, $value=null){
		
		if($value){
			$criteria->add(LinkEmployeeLeavePeer::MONTH   , LinkEmployeeLeavePeer::MONTH."=month('{$value}')",Criteria::CUSTOM     );
			$criteria->add(LinkEmployeeLeavePeer::YEAR    , LinkEmployeeLeavePeer::YEAR."=year('{$value}')" ,Criteria::CUSTOM    );
			//$criteria->add(EmployeePeer::SECTION_ID  , $value );
		}
	}
	protected function addLeaveTypeIdColumnCriteria(Criteria $criteria, $field, $value=null){

		if(is_array($value) && count($value) > 0){
			$criteria->add(LinkEmployeeLeavePeer::LEAVE_TYPE_ID  , $value ,Criteria::IN );
			$criteria->addGroupByColumn( LinkEmployeeLeavePeer::LEAVE_TYPE_ID );
		}
	}


	public function buildCriteria(array $values){
		/*@var $c Criteria*/
		$c = parent::buildCriteria( $values );
		$c->clearSelectColumns();
		$c->addSelectColumn('ROUND(sum('.LinkEmployeeLeavePeer::LEAVE_PERIOD.')/3600,2) as sum');
		$c->addSelectColumn(LinkEmployeeLeavePeer::LEAVE_TYPE_ID .' as leave_type_id');
		return $c;
	}



}
